// Project name:JavaRedis
// Creator:muhong
// Date time:2022/12/14,11:24 下午
// Name:ThreadPerTaskExecutor

package org.gmh.util.concurrent;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;

public final class ThreadPerTaskExecutor implements Executor {

    private final ThreadFactory threadFactory;

    protected ThreadPerTaskExecutor(ThreadFactory threadFactory){
        if (threadFactory == null){
            throw new NullPointerException("thread factory");
        }
        this.threadFactory = threadFactory;
    }

    @Override
    public void execute(Runnable command) {
        threadFactory.newThread(command).start();
    }
}
